rsiso <- function(pt, ...)
{
	if(!is.matrix(pt)) stop ("first argument pt must be a 2 dimensional matrix");

	bagi=double( (length(pt)/2)^4 );
	numi=(length(pt)/2);

x = matrix(pt[,1],nc=1)
y = matrix(pt[,2],nc=1)


plot(pt,pch='.',xlab='Diastolic Blood Pressure (DBP)',ylab='Cholesterol (HDL)')
#for(i in 1:(length(x)) ) {
#for(j in (i+1):(length(y)) ) {
#segments(x[i],y[i],x[j],y[j])
#}
#}

        rtvalue = .C("GetBag",
                    ptX=as.double(pt[,1]), 
                    ptY=as.double(pt[,2]), 
                    bag=double( (length(pt)/2)^4 ), 	
                    num=as.integer(numi),
                    bagsz=integer(c(1)),
                    center=double( (length(pt)/2)^4 ), 	
                    cSize=integer(c(1)),
                    PACKAGE = "Risors");

##truncate bag (2d matrix byrow) to up till num/2
bag = matrix(rtvalue$bag[1:(rtvalue$bagsz)],nc=2,byrow=TRUE)
center = matrix(rtvalue$center[1:(rtvalue$cSize)],nc=2,byrow=TRUE)
##points(rtvalue$bagx,rtvalue$bagy,pch='x')
##return (bag);
##print(bag)
##find convex hull
x=chull(bag[,1],bag[,2]);

y=matrix(rnorm(length(x)*2),nc=2);
for(i in 1:(length(x)) ) {
	y[i,1]=bag[x[i],1];
	y[i,2]=bag[x[i],2];
}


#y=matrix(y,nc=2);
polygon(y[,1],y[,2],col="#7799ff")

cIndex=chull(center[,1],center[,2]);

cent=matrix(rnorm(length(cIndex)*2),nc=2);
for(i in 1:(length(cIndex)) ) {
	cent[i,1]=center[cIndex[i],1];
	cent[i,2]=center[cIndex[i],2];
}
print(rtvalue$cSize)
polygon(cent[,1],cent[,2],col="yellow")

points(pt[,1],pt[,2],pch=20)
md=rsmed(pt)
points(md[1],md[2],pch='*',col='red')

	return (y);

}

